﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Documents;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Caliburn.Micro;
using ThunderboltInterfaceSharp.Views;

namespace ThunderboltInterfaceSharp.ViewModels;

public class LoginViewModel:Screen
{
	public List<string> Accounts { get; set; }
	public ImageSource PreviewImage { get; set; }
	public ObservableCollection<int> TelephoneOwnership { get; set; }
	public bool IsScanCodeShow { get; set; }
	public bool IsInputShow { get =>!IsScanCodeShow;private set=> IsScanCodeShow =!value; }
	private LoginView _loginView;
	public LoginViewModel()
	{
		Accounts = new List<string>()
		{
			"A",
			"B",
			"C"
		};
		TelephoneOwnership = new ObservableCollection<int>()
		{
			86,12,14,10
		};
	}

	protected override void OnViewLoaded(object view)
	{
		_loginView = (LoginView)view;
		BitmapImage bImage = new BitmapImage();
		bImage.BeginInit();
		bImage.UriSource = new Uri($"../Resources/Images/qrcodeRunoob.png", UriKind.Relative);
		bImage.EndInit();
		PreviewImage = bImage; //完成图片的更新

	}

	public void BtnClose()
	{
		_loginView.Close();
	}

	public void BtnCodeScanInterface()
	{
		IsScanCodeShow = !IsScanCodeShow;
		BitmapImage bImage = new BitmapImage();
		bImage.BeginInit(); 
		bImage.UriSource = IsScanCodeShow? 
			new Uri($"../Resources/Images/BLUEWOLF.jpg", UriKind.Relative)
			: new Uri($"../Resources/Images/qrcodeRunoob.png", UriKind.Relative);
		bImage.EndInit();
		PreviewImage = bImage; //完成图片的更新
	}

	public void BtnCodeScanInterfaceMouseHover()
	{
		//if (_loginView.popup.IsOpen == false)
		//{
		//	_loginView.popup.IsOpen = true;
		//	double r = 5;
		//	_loginView.popup.HorizontalOffset = (_loginView.popup_grid.ActualWidth + 2 * r - _loginView.ImageSwitch.ActualWidth) / (-2);
		//	_loginView.path.Data = GetPathGeometry(_loginView.popup_grid.ActualWidth, _loginView.popup_grid.ActualHeight, r);
		//}
	
	}

	private PathGeometry GetPathGeometry(double width, double height, double r)
	{
		width += 2 * r;
		height += 2 * r;
		PathGeometry geometry = new PathGeometry();
		PathFigure pathfigure = new PathFigure();
		pathfigure.IsClosed = true;
		pathfigure.StartPoint = new Point(r, 0);
		pathfigure.Segments.Add(new ArcSegment(new Point(0, r), new Size(r, r), 0, false, SweepDirection.Counterclockwise, true));
		pathfigure.Segments.Add(new LineSegment(new Point(0, height + r), true));
		pathfigure.Segments.Add(new ArcSegment(new Point(r, height + 2 * r), new Size(r, r), 0, false, SweepDirection.Counterclockwise, true));
		pathfigure.Segments.Add(new LineSegment(new Point(width / 2, height + 2 * r), true));
		pathfigure.Segments.Add(new LineSegment(new Point(width / 2 + r, height + 3 * r), true));
		pathfigure.Segments.Add(new LineSegment(new Point(width / 2 + 2 * r, height + 2 * r), true));
		pathfigure.Segments.Add(new LineSegment(new Point(width + r, height + 2 * r), true));
		pathfigure.Segments.Add(new ArcSegment(new Point(width + 2 * r, height + r), new Size(r, r), 0, false, SweepDirection.Counterclockwise, true));
		pathfigure.Segments.Add(new LineSegment(new Point(width + 2 * r, r), true));
		pathfigure.Segments.Add(new ArcSegment(new Point(width + r, 0), new Size(r, r), 0, false, SweepDirection.Counterclockwise, true));
		geometry.Figures.Add(pathfigure);
		return geometry;
	}

}